package ModelLayer;
import java.util.ArrayList;


/**
 * Write a description of class SupplierContainer here.
 * 
 * @author Group1 
 * @version 2011-06-08
 */
public class SupplierContainer
{
    // instance variables - replace the example below with your own
    private ArrayList<Supplier> supplier;
    private static SupplierContainer _instance = null;

    /**
     * Constructor for objects of class SupplierContainer
     */
    private SupplierContainer()
    {
        supplier = new ArrayList<Supplier>();
        addSupplerToContainer();
    }
    
        /**
     * Creates an instance of SupplierContainer
     * @return Returns an instance of SupplierContainer
     */
    public static SupplierContainer getInstance()
    {
        if(_instance == null)
        {
            _instance = new SupplierContainer();
        }
        return _instance;
    }
    
    /**
     * create a supplier to SupplierContainer
     * @param take a parameter of type Supplier
     */
    public void createSupplier(Supplier newsupplier)
    {
        supplier.add(newsupplier);
    }

    /**
     * Creates 3 supplier to SupplierContainer, supplier that are in the start.
     * @param take a parameter of type Supplier
     */    
    public void addSupplerToContainer()
    {
        Supplier s1 = new Supplier("NKT", "Oesteralle 3", "Aalborg", 9000, 96454545, "7 days");
        Supplier s2 = new Supplier("Fisher", "Vilddukten 10", "Aarhus", 8000, 99225544, "24 hours");
        Supplier s3 = new Supplier("Dewalt", "Knollevej 65", "Odense", 5000, 50205400, "2 days");
        
        supplier.add(s1);
        supplier.add(s2);
        supplier.add(s3);
    }
    
    /**
     * Find a supplier from the SupplierContainer
     * @param name Name of the supplier
     */
    public Supplier findSupplierByName(String name)
    {
        boolean found = false;
        int index = 0;
        Supplier s = null;
        while (index < supplier.size() && !found)
        {
            if (supplier.get(index).getName().equals(name))
            {
                found = true;
                s = supplier.get(index);
            }
            index++;
        }

        return s;
    }
    
    /**
     * Delete supplier from the SupplierContainer
     * @param take an objekt of the type supplier
     */
    public void deleteSupplier(String name)
    {
        Supplier s = findSupplierByName(name);
        supplier.remove(s);
    }
    
    /**
     * Update the supplier in SupplierContainer
     * @param address Address of the supplier
     * @param city City of the supplier
     * @param ZIPCode ZIPCode of the supplier
     */
    public void updateSupplierAddressCityZIP(String name, String address, String city, int ZIPCode)
    {
        Supplier s = findSupplierByName(name);
        s.setAddress(address);
        s.setCity(city);
        s.setZIPCode(ZIPCode);
    }
    
    /**
     * Update the supplier in SupplierContainer
     * @param phoneNumber PhoneNumber of the supplier
     * @param deliveryTime Delivery time of the supplier
     */
    public void updateSupplierPhoneDeliveryTime(String name, int phoneNumber, String deliveryTime)
    {
        Supplier s = findSupplierByName(name);
        s.setPhoneNumber(phoneNumber);
        s.setDeliveryTime(deliveryTime);
    }
    
    /**
     * Lists all Supplier in the SupplierContainer 
     */
    public ArrayList<Supplier> listAllSupplier()
    {   
             return supplier;  
    }
}
